#!/bin/sh

if [ -z "$1" ] ; then
    case `echo "$0" | /bin/sed 's/^.*\/\(.*\)/\1/g'` in
	S??*) rc="start" ;;
	K??*) rc="stop" ;;
	*) rc="usage" ;;
    esac
else
    rc="$1"
fi

case "$rc" in
    start)
	echo -n "starting service sendmail "
        # Is it only my setup that has group-writeable root dir?
        # sendmail does not like at all.
        chmod og-w /
	/opt/sbin/sendmail -L sm-mta -bd -q1h
        echo ok
	;;
    stop)
	echo "stopping service sendmail"
	sendpid=`pidof sendmail`
	if [ -n "$sendpid" ]; then
	    kill $sendpid  > /dev/null 2>&1
	fi
	;;
    restart)
	"$0" stop
	sleep 1
	"$0" start
	;;
    *)
	echo "Usage: $0 (start|stop|restart|usage)"
	;;
esac
